﻿#region references
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

/* Project dependencies */
using IcaGames.Logging;
using IcaGames.Database;
using IcaGames.Objects;
using IcaGames.Database.ObjectManagement;
#endregion

public partial class Games : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                /* Get the search results for the search query */
                string searchQuery = Request.QueryString["c"];

                List<Game> searchResults = new List<Game>();
                if (searchQuery.Equals("all")) 
                { 
                    searchQuery = string.Empty; 
                    searchResults = DatabaseStore.GetSearchResults(searchQuery);
                }
                else
                {
                    searchResults = DatabaseStore.GetSearchResultsByPlatform(searchQuery);
                }

                ucSearchResults._gameSearchResults = searchResults.Count.ToString();
                ucSearchResults._gvGamesDataSource = searchResults;

                List<Publisher> publishers = PublisherManagement.GetPublishers(searchQuery);
                ucSearchResults._publisherSearchResults = publishers.Count.ToString();
                ucSearchResults._gvPublisherDataSource = publishers;
            }
            catch (Exception ex)
            {
                Log.CreateLog("Exception while getting QueryString from frontpage", "GAMES");
                Log.CreateLog(ex.Message, "GAMES");
            }
        }
    }
}
